// multiselect.js
var app = getApp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        hiddenToast: true,
        totalindex: '0'


    },


    btn_select: function(e) {


        var index = e.target.dataset.id;


        if (index !== -1) {
            var val = this.data.config[index].selected ? false : true;
            this.setData({
                ['config[' + index + '].selected']: val
            });

        }
    },



    sure_btn: function() {

        var pages = getCurrentPages();
        var currPage = pages[pages.length - 1]; //当前页面
        var prevPage = pages[pages.length - 2]; //上一个页面
        var textstring = "";

        for (var i = 0; i < this.data.config.length; i++) {
            if (this.data.config[i].selected) {
                if (textstring == "") {
                    textstring = textstring + this.data.config[i].title
                } else {
                    textstring = textstring + "," + this.data.config[i].title
                }

            }
        }

        if (this.data.totalindex == "1") {
            prevPage.valuechange({

                text_title: textstring
            })
        } else {
            prevPage.valuechange({

                text_titletwo: textstring
            })
        }



        wx.navigateBack({
            delta: 1
        })
    },
    toastHidden: function() {
        this.setData({
            hiddenToast: true
        })
    },
    onLoad: function(options) {


        var that = this;
        let group = "";
        let finalindex = options.finalindex;
        let index = options.index;
        var text_title = "";
        if (index == "1") {
            text_title = options.text_title;
        } else {
            text_title = options.text_titletwo;
        }
        if (finalindex == "1") {
            if (index == "1") {
                group = "发需求-您想要做"
            } else {
                group = "发需求-您从事的行业"
            }
        } else if (finalindex == "3") {
            if (index == "1") {
                group = "小程序-您目前在运营的微信公众号"
            } else {
                group = "小程序-您从事的行业"
            }
        }
        console.log(group)
        app.util.request({
            'url': 'entry/wxapp/tags',
            data: {
                m: 'llt_xappsc',
                group: group
            },
            'cachetime': '30',
            success: function(res) {
                var configdata = res.data.data
                for (let i = 0; i < configdata.length; i++) {

                    if (configdata[i].title == text_title) {
                        configdata[i].selected = true
                    }
                }

                that.setData({
                    totalindex: index,
                    config: configdata
                })
            }
        });

    },
    onShareAppMessage: function() {

    },

})